<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>骡窝窝系统管理平台</title>
    <#include "../common/header.ftl"/>
    <link href="/js/plugins/chosen/component-chosen.css" rel="stylesheet">
    <script src="/js/plugins/chosen/chosen.jquery.js"></script>
    <style type="text/css">
        .chosen-container {
            width: 250px !important;
        }
    </style>
    <script type="text/javascript">
        $(function(){
                $("#query").click(function(){
                    $("#searchForm").submit();
                });


                //点击添加按钮
                $("#addStrategyBtn").click(function(){
                    $("#editForm")[0].reset();
                    $("#strategyTitle").val( $("#strategySelect option:selected").text());
                    $("#strategyId").val($("#strategySelect option:selected").val());
                    $("#strategyModal").modal("show");
                });


                $("#editForm").ajaxForm(function(data){
                    $.messager.confirm("提示","保存成功",function(){
                        window.location.reload();
                    });
                });

                //点击保存
                $("#saveBtn").click(function(){
                    if($("#strategyTitle").val()==null||$("#strategyTitle").val()==''||$("#travelSelect").val()==null||$("#travelSelect").val()==''){
                        $.messager.confirm("提示","保存失败，攻略和游记不能为空！");
                        return;
                    }
                    $("#editForm").submit();
                });

                //点击删除
                $(".del_Btn").click(function () {
                    var strategyId = $("#strategySelect option:selected").val();
                    var json=$(this).data("jsonstr");
                    $.post("/strategyTravel/deleteRelation.do",{strategyId:strategyId,travelId:json.id},function (data) {
                        if(data.success){
                            $.messager.confirm("提示","删除成功",function(){
                                window.location.reload();
                            });
                        }
                    })
                })
            

            //查询攻略
            $.get('/strategy/selectAll.do',function (regions) {
                var html;
                for(let i=0;i<regions.length;i++){
                    html+='<option value='+regions[i].id+'>'+regions[i].title+'</option>';
                }
                $('#strategySelect').append(html);

                //回显
                $("#strategySelect option[value='${qo.strategyId!""}']").prop("selected", true);

                $('#strategySelect').chosen({
                    no_results_text: "无相关攻略!",
                    disable_search_threshold: 5,//选项小于10时不显示搜索框
                });

            })

            //查询游记
            $.get('/travel/selectRelease.do',function (regions) {
                var html;
                for(let i=0;i<regions.length;i++){
                    html+='<option value='+regions[i].id+'>'+regions[i].title+'</option>';
                }
                $('#travelSelect').append(html);

                $('#travelSelect').chosen({
                    no_results_text: "无相关游记!",
                    disable_search_threshold: 5,//选项小于5时不显示搜索框
                });

            })



        });
    </script>
</head>

<body>
<div class="container">
<#include "../common/top.ftl"/>
    <div class="row">
        <div class="col-sm-3">
		<#assign currentMenu = "strategyTravel" />
				<#include "../common/menu.ftl" />
        </div>
        <div class="col-sm-9">
            <div class="page-header">
                <h3>大家都在看</h3>
            </div>
            <div class="row">
                <!-- 提交分页的表单 -->
                <form id="searchForm" class="form-inline" method="post" action="/strategyTravel/list.do">
                    <input type="hidden" name="currentPage" id="currentPage" value="1"/>
                    <div class="form-group">
                    </div>
                    <div class="form-group">
                        <label >攻略搜索</label>
                        <select id="strategySelect" name="strategyId" class="form-control form-control-chosen" data-placeholder="请选择所属攻略" style="width: 200px">
                            <option></option>
                        </select>
                    </div>
                    <div class="form-group">
                        <button id="query" type="button" class="btn btn-success"><i class="icon-search"></i> 查询</button>
                        <a href="javascript:void(-1);" class="btn btn-success" id="addStrategyBtn">添加关联</a>
                    </div>
                </form>
            </div>
            <div class="row">
                <table class="table">
                    <thead>
                    <tr>
                        <th>关联游记</th>
                    </tr>
                    </thead>
                    <tbody>
					<#list (travels)! as vo>
                    <tr>
                        <td>${(vo.title)!""}</td>
                        <td>
                            <a href="/travelRelease/list.do?travelId=${vo.id}" target="_blank" >查看游记文章</a>
                        </td>
                        <td>
                            <a href="javascript:void(-1);" class="del_Btn" data-jsonstr='${vo.json}'>删除</a>
                        </td>
                    </tr>
					</#list>
                    </tbody>
                </table>

                <div style="text-align: center;">
                    <ul id="pagination" class="pagination"></ul>
                </div>
            </div>
        </div>
    </div>
</div>

<div id="strategyModal" class="modal" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">编辑/增加</h4>
            </div>
            <div class="modal-body">
                <form id="editForm" class="form-horizontal" method="post" enctype="multipart/form-data" action="/strategyTravel/insertRelation.do" style="margin: -3px 118px">
                    <input id="strategyId" type="hidden" name="strategyId" value="" />
                    <div class="form-group">
                        <label class="col-sm-4 control-label">所属攻略</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="strategyTitle" readonly >
                        </div>
                    </div>
                  <div class="form-group">
                        <label class="col-sm-4 control-label">关联游记</label>
                        <div class="col-sm-6">
                            <select id="travelSelect" name="travelId" class="form-control form-control-chosen" data-placeholder="请选择关联的游记">
                                <option></option>
                            </select>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <a href="javascript:void(0);" class="btn btn-success" id="saveBtn" aria-hidden="true">保存</a>
                <a href="javascript:void(0);" class="btn" data-dismiss="modal" aria-hidden="true">关闭</a>
            </div>
        </div>
    </div>
</div>
</body>
</html>